package com.santiao.fuel.ui.activity

import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.santiao.fuel.R
import com.santiao.fuel.utils.DisplayUtil
import com.santiao.publics.ui.SettingFragment


/**
 * 燃气费查询页面
 */
class gas_price_query : AppCompatActivity() {

    override fun onStart() {
        super.onStart()
        initData();
    }


    /**
     * 初始化数据
     */
    private fun initData() {

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gas_price_query)
        DisplayUtil.initActionBar(this)
        initView();

    }


    /**
     * 初始化view
     */
    private fun initView() {


        // 初始化actionBar
        val gasBarRootView = findViewById<RelativeLayout>(R.id.gas_bar)
        val page_title = gasBarRootView.findViewById<TextView>(R.id.page_title)
        val page_back = gasBarRootView.findViewById<ImageView>(R.id.page_back)
        page_title.text = "燃气费查询"
        page_back.setOnClickListener {
            finish()
        }

        val query = findViewById<TextView>(R.id.startQuery)
        query.setOnClickListener{

            start_WeChat()
        }
        SettingFragment.adLoad(1, null, findViewById(R.id.fl_content_1), this, this)

    }


    fun start_WeChat(){
        try {
            val intent = Intent()
            val cmp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI")
            intent.setAction(Intent.ACTION_MAIN)
            intent.addCategory(Intent.CATEGORY_LAUNCHER)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.setComponent(cmp)
            startActivityForResult(intent, 0)
        } catch (e: Exception) {

            Toast.makeText(this , "请检查是否已经安装微信" , Toast.LENGTH_SHORT).show()
        }
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
//        if (requestCode == 0) {
//            Toast.makeText(this , "微信跳转成功" , Toast.LENGTH_LONG).show()
//            return
//        }else{
//            Toast.makeText(this , "请先安装微信",Toast.LENGTH_SHORT).show()
//            Log.e("TAG", "onActivityResult: 微信跳转失败，可能没有安装微信", )
//        }
    }
}